package com.example.xianji.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.activity.Main_Choose_DaTingActivity;
import com.example.xianji.activity.Main_ChuangJain_ProductActivity;
import com.example.xianji.activity.Main_LoginActivity;
import com.example.xianji.activity.Main_QiYe_RuZhuActivity;
import com.example.xianji.activity.Main_SearchActivity;
import com.example.xianji.activity.Main_Send_Want_Buy_ProductActivity;
import com.example.xianji.R;
import com.example.xianji.adapter.ErJiFuwu_Fenlei_Adapter;
import com.example.xianji.adapter.FuWu_FenLei_Adapter;
import com.example.xianji.adapter.product_Adapter;
import com.example.xianji.BGARefresh.BGARefreshLayout;
import com.example.xianji.BGARefresh.BGARefreshLayout.BGARefreshLayoutDelegate;
import com.example.xianji.bean.YiJi_Class;
import com.example.xianji.bean.news;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 选型大厅
 *
 * @author me
 */
public class ChooseDaTingFragment extends Fragment implements
        BGARefreshLayoutDelegate, OnClickListener {
    /******************************** 选型大厅列表页面 ***************************/
    private View view;
    private BGARefreshLayout xuanxing_RefreshLayout;
    private ListView xuan_xing_mlistView;
    private RelativeLayout xuanxing_relative_back,
            relativelayout_xuanxing_hangye_fenlei,
            relativelayout_send_products, relativelayout_send_want_buy;

    private product_Adapter mproduct_Adapter;//选型大厅 列表适配器
    private int page = 1;
    private ImageView xuanxing_liebiao_search;
    private TextView product_choose_name, text_qiye_hangye_fenlei;
    private LinearLayout linear_fenlei_shuaixuan;
    private int cid = 0;
    private ArrayList<news> list = new ArrayList<news>();
    private int indext = 0;
    private ArrayList<YiJi_Class> yiji_list = new ArrayList<YiJi_Class>();
    private ArrayList<YiJi_Class> erji_list = new ArrayList<YiJi_Class>();
    private ArrayList<YiJi_Class> sanji_list = new ArrayList<YiJi_Class>();
    private ArrayList<YiJi_Class> siji_list = new ArrayList<YiJi_Class>();
    private ArrayList<YiJi_Class> wuji_list = new ArrayList<YiJi_Class>();
    private ArrayList<YiJi_Class> total_list = new ArrayList<YiJi_Class>();
    private ListView xuanxing_dating_listview, xuanxing_dating_listview_two,
            xuanxing_dating_listview_three, xuanxing_dating_listview_four,
            xuanxing_dating_listview_five;
    private FuWu_FenLei_Adapter mFuWu_FenLei_Adapter;//选型大厅---行业分类一级
    private ErJiFuwu_Fenlei_Adapter mErJi_FuWuFenlei_Adapter,
            mSanji_FuWuFenlei_Adapter, mSiji_FuWuFenlei_Adapter,
            mWuji_FuWuFenlei_Adapter;////选型大厅---行业分类二级,三级,四级
    private View xuanxing_translation_view;
    public static String text_product_context = "";// 产品搜索关键词
    private int height;
    //    private SharedPreferences sp;
//    private Editor ed;
    private ImageView choose_product_image_load;
    private AnimationDrawable mAnimationDrawable;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                mAnimationDrawable.stop();
                choose_product_image_load.setVisibility(View.GONE);
                xuan_xing_mlistView.setAdapter(mproduct_Adapter);
                xuanxing_RefreshLayout.endRefreshing();
            }
            if (msg.what == 2) {
                mproduct_Adapter.notifyDataSetChanged();
                xuanxing_RefreshLayout.endLoadingMore();
            }
            if (msg.what == 3) {
                // 一级分类显示
                xuanxing_translation_view.setVisibility(View.VISIBLE);
                xuanxing_dating_listview.setVisibility(View.VISIBLE);
                xuanxing_dating_listview.setAdapter(mFuWu_FenLei_Adapter);
                xuanxing_dating_listview
                        .setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent,
                                                    View view, int position, long id) {
                                cid = yiji_list.get(position).getId();
                                mFuWu_FenLei_Adapter.setPosition(position);
                                mFuWu_FenLei_Adapter.notifyDataSetChanged();
                                // 点击请求二级分类
                                XJApplication.cachThreadPool
                                        .execute(new Runnable() {

                                            @Override
                                            public void run() {
                                                // stub
                                                get_fenlei_sanji_tag(4,
                                                        erji_list,
                                                        xuanxing_dating_listview_two);
                                            }
                                        });
                                xuanxing_dating_listview_three
                                        .setVisibility(View.GONE);
                                xuanxing_dating_listview_four
                                        .setVisibility(View.GONE);
                                xuanxing_dating_listview_five
                                        .setVisibility(View.GONE);
                            }
                        });
            }
            if (msg.what == 4) {
                // 二级分类
                xuanxing_dating_listview_two.setVisibility(View.VISIBLE);
                xuanxing_dating_listview_two
                        .setAdapter(mErJi_FuWuFenlei_Adapter);
                mErJi_FuWuFenlei_Adapter.setPosition(-1);
                mErJi_FuWuFenlei_Adapter.notifyDataSetChanged();
                xuanxing_dating_listview_two
                        .setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent,
                                                    View view, int position, long id) {
                                cid = erji_list.get(position).getId();
                                mErJi_FuWuFenlei_Adapter.setPosition(position);
                                mErJi_FuWuFenlei_Adapter.notifyDataSetChanged();
                                // 请求三级分类
                                XJApplication.cachThreadPool
                                        .execute(new Runnable() {

                                            @Override
                                            public void run() {
                                                // stub
                                                get_fenlei_sanji_tag(5,
                                                        sanji_list,
                                                        xuanxing_dating_listview_three);
                                            }
                                        });

                                xuanxing_dating_listview_four
                                        .setVisibility(View.GONE);
                                xuanxing_dating_listview_five
                                        .setVisibility(View.GONE);
                            }
                        });

            }
            if (msg.what == 5) {
                // 三级分类列表显示
                xuanxing_dating_listview_three.setVisibility(View.VISIBLE);
                xuanxing_dating_listview_three
                        .setAdapter(mSanji_FuWuFenlei_Adapter);
                mSanji_FuWuFenlei_Adapter.setPosition(-1);
                mSanji_FuWuFenlei_Adapter.notifyDataSetChanged();
                xuanxing_dating_listview_three
                        .setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent,
                                                    View view, int position, long id) {
                                cid = sanji_list.get(position).getId();
                                mSanji_FuWuFenlei_Adapter.setPosition(position);
                                mSanji_FuWuFenlei_Adapter
                                        .notifyDataSetChanged();
                                // 请求四级分类列表数据
                                XJApplication.cachThreadPool
                                        .execute(new Runnable() {

                                            @Override
                                            public void run() {
                                                // stub
                                                get_fenlei_sanji_tag(6,
                                                        siji_list,
                                                        xuanxing_dating_listview_four);
                                            }
                                        });

                                xuanxing_dating_listview_five
                                        .setVisibility(View.GONE);
                            }
                        });

            }
            if (msg.what == 6) {
                // 四级分类列表显示
                xuanxing_dating_listview_four.setVisibility(View.VISIBLE);
                xuanxing_dating_listview_four
                        .setAdapter(mSiji_FuWuFenlei_Adapter);
                mSiji_FuWuFenlei_Adapter.setPosition(-1);
                mSiji_FuWuFenlei_Adapter.notifyDataSetChanged();
                xuanxing_dating_listview_four
                        .setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent,
                                                    View view, int position, long id) {
                                cid = siji_list.get(position).getId();
                                text_qiye_hangye_fenlei.setText(siji_list.get(
                                        position).getName());
                                mSiji_FuWuFenlei_Adapter.setPosition(position);
                                mSiji_FuWuFenlei_Adapter.notifyDataSetChanged();

                                // 请求五级分类列表数据
                                // get_fenlei_sanji_tag(7,wuji_list,xuanxing_dating_listview_five);
                                linear_fenlei_shuaixuan
                                        .setVisibility(View.GONE);
                                xuanxing_translation_view
                                        .setVisibility(View.GONE);
                                XJApplication.cachThreadPool
                                        .execute(new Runnable() {

                                            @Override
                                            public void run() {
                                                // stub
                                                get_qiye_data();
                                            }
                                        });
                            }
                        });
            }
            if (msg.what == 7) {
                // 五级分类列表显示
                xuanxing_dating_listview_five.setVisibility(View.VISIBLE);
                xuanxing_dating_listview_five
                        .setAdapter(mWuji_FuWuFenlei_Adapter);
                xuanxing_dating_listview_five
                        .setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent,
                                                    View view, int position, long id) {
                                cid = wuji_list.get(position).getId();
                                mWuji_FuWuFenlei_Adapter.setPosition(position);
                                mWuji_FuWuFenlei_Adapter.notifyDataSetChanged();
                                linear_fenlei_shuaixuan
                                        .setVisibility(View.GONE);
                                xuanxing_translation_view
                                        .setVisibility(View.GONE);
                                get_qiye_data();
                            }
                        });
            }
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.choose_dating_fragment, container,
                false);
        init(savedInstanceState);
        XJApplication.cachThreadPool.execute(new Runnable() {

            @Override
            public void run() {
                get_qiye_data();
            }
        });
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void init(Bundle savedInstanceState) {
        xuanxing_RefreshLayout = (BGARefreshLayout) view
                .findViewById(R.id.xuanxing_RefreshLayout);
//        sp = getActivity().getSharedPreferences("text",
//                getActivity().MODE_PRIVATE);
//        ed = sp.edit();

        relativelayout_xuanxing_hangye_fenlei = (RelativeLayout) view
                .findViewById(R.id.relativelayout_xuanxing_hangye_fenlei);

        mFuWu_FenLei_Adapter = new FuWu_FenLei_Adapter(getActivity(), yiji_list);
        mErJi_FuWuFenlei_Adapter = new ErJiFuwu_Fenlei_Adapter(getActivity(),
                erji_list);
        mSanji_FuWuFenlei_Adapter = new ErJiFuwu_Fenlei_Adapter(getActivity(),
                sanji_list);

        mSiji_FuWuFenlei_Adapter = new ErJiFuwu_Fenlei_Adapter(getActivity(),
                siji_list);
        mWuji_FuWuFenlei_Adapter = new ErJiFuwu_Fenlei_Adapter(getActivity(),
                wuji_list);

        xuan_xing_mlistView = (ListView) view
                .findViewById(R.id.xuan_xing_mlistView);
        xuanxing_translation_view = (View) view
                .findViewById(R.id.xuanxing_translation_view);

        xuanxing_dating_listview = (ListView) view
                .findViewById(R.id.xuanxing_dating_listview);
        xuanxing_dating_listview_two = (ListView) view
                .findViewById(R.id.xuanxing_dating_listview_two);
        xuanxing_dating_listview_three = (ListView) view
                .findViewById(R.id.xuanxing_dating_listview_three);
        xuanxing_dating_listview_four = (ListView) view
                .findViewById(R.id.xuanxing_dating_listview_four);
        xuanxing_dating_listview_five = (ListView) view
                .findViewById(R.id.xuanxing_dating_listview_five);
        text_qiye_hangye_fenlei = (TextView) view
                .findViewById(R.id.text_qiye_hangye_fenlei);
        relativelayout_send_products = (RelativeLayout) view
                .findViewById(R.id.relativelayout_send_products);
        relativelayout_send_want_buy = (RelativeLayout) view
                .findViewById(R.id.relativelayout_send_want_buy);
        choose_product_image_load = (ImageView) view.findViewById(R.id.choose_product_image_load);

        mAnimationDrawable = (AnimationDrawable) choose_product_image_load.getDrawable();

        mAnimationDrawable.start();
        WindowManager wm = (WindowManager) getActivity().getSystemService(
                Context.WINDOW_SERVICE);
        height = wm.getDefaultDisplay().getHeight() / 2;

        linear_fenlei_shuaixuan = (LinearLayout) view
                .findViewById(R.id.linear_fenlei_shuaixuan);
        xuanxing_relative_back = (RelativeLayout) view
                .findViewById(R.id.xuanxing_relative_back);

        if (Contant.choose_dating_back == 1) {
            // 是主页面进入的
            xuanxing_relative_back.setVisibility(View.INVISIBLE);

        } else {
            xuanxing_relative_back.setVisibility(View.VISIBLE);
        }

        xuanxing_liebiao_search = (ImageView) view
                .findViewById(R.id.xuanxing_liebiao_search);
        product_choose_name = (TextView) view
                .findViewById(R.id.product_choose_name);

        product_choose_name.setText("选型大厅");
        mproduct_Adapter = new product_Adapter(getActivity(), list);
        xuanxing_RefreshLayout.setDelegate(this);
        processLogic(savedInstanceState);
        xuanxing_relative_back.setOnClickListener(this);
        xuanxing_liebiao_search.setOnClickListener(this);
        xuanxing_translation_view.setOnClickListener(this);
        relativelayout_xuanxing_hangye_fenlei.setOnClickListener(this);
        relativelayout_send_want_buy.setOnClickListener(this);
        relativelayout_send_products.setOnClickListener(this);
        xuan_xing_mlistView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                xuanxing_RefreshLayout.endRefreshing();
                xuanxing_RefreshLayout.endLoadingMore();
                Intent intent = new Intent(getActivity(),
                        Main_Choose_DaTingActivity.class);
                intent.putExtra("product_id", list.get(position).getId());
                getActivity().startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.xuanxing_relative_back) {
            text_product_context = "";
            getActivity().finish();

        } else if (v.getId() == R.id.xuanxing_liebiao_search) {
            Intent intent = new Intent(getActivity(), Main_SearchActivity.class);
            intent.putExtra("search", 7);
            startActivity(intent);
        } else if (v.getId() == R.id.relativelayout_xuanxing_hangye_fenlei) {
            cid = 0;
            linear_fenlei_shuaixuan
                    .setLayoutParams(new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT, height));
            linear_fenlei_shuaixuan.setVisibility(View.VISIBLE);
            xuanxing_translation_view.setVisibility(View.VISIBLE);
            XJApplication.cachThreadPool.execute(new Runnable() {
                @Override
                public void run() {
                    get_fenlei_sanji_tag(3, yiji_list, xuanxing_dating_listview);
                }
            });

        } else if (v.getId() == R.id.xuanxing_translation_view) {
            linear_fenlei_shuaixuan.setVisibility(View.GONE);
            xuanxing_translation_view.setVisibility(View.GONE);

        } else if (v.getId() == R.id.relativelayout_send_products) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 1) {
                    // 可以申请企业入驻
                    getActivity().startActivity(
                            new Intent(getActivity(),
                                    Main_QiYe_RuZhuActivity.class));

                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 0) {
                    Toast.makeText(getActivity(), "正在审核，请耐心等待", Toast.LENGTH_SHORT).show();
                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 2) {
                    // 审核失败，可以再次申请企业入驻
                    getActivity().startActivity(
                            new Intent(getActivity(),
                                    Main_QiYe_RuZhuActivity.class));
                } else if (PreferenceEngine.getInstance().getInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, 5) == 3) {
                    Intent intent = new Intent(getActivity(),
                            Main_ChuangJain_ProductActivity.class);
                    intent.putExtra("product_come_from",
                            Contant.product_come_from_send);
                    startActivity(intent);
                }
            } else {
                Contant.come_from_fuwuDetail = 1;// 表明从产品列表页面进入的登录页面，登录成功在resume
                // 中要加载是否升级为企业用户的数据
                startActivity(new Intent(getActivity(),
                        Main_LoginActivity.class));
            }
        } else if (v.getId() == R.id.relativelayout_send_want_buy) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                Intent intent = new Intent(getActivity(),
                        Main_Send_Want_Buy_ProductActivity.class);
                intent.putExtra("come_from_fuwu_send_buy",
                        Contant.come_from_product_send_buy);
                startActivity(intent);
            } else {
                startActivity(new Intent(getActivity(),
                        Main_LoginActivity.class));
            }
        }
    }

    @Override
    public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
        page = 1;
        XJApplication.cachThreadPool.execute(new Runnable() {

            @Override
            public void run() {
                get_qiye_data();
            }
        });

    }

    @Override
    public boolean onBGARefreshLayoutBeginLoadingMore(
            BGARefreshLayout refreshLayout) {
        page++;
        XJApplication.cachThreadPool.execute(new Runnable() {

            @Override
            public void run() {
                get_qiye_data_more();
            }
        });

        return true;
    }

    protected void processLogic(Bundle savedInstanceState) {
        xuanxing_RefreshLayout
                .setRefreshViewHolder(new com.example.xianji.BGARefresh.BGANormalRefreshViewHolder(
                        getActivity(), true));
    }

    public void get_qiye_data() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("page", 1 + "");
        parms.addBodyParameter("cid", cid + "");
        parms.addBodyParameter("k", text_product_context);
        httpUtils.send(HttpMethod.POST, Contant.product_liebiao, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        Toast.makeText(getActivity(), "网络异常", Toast.LENGTH_SHORT).show();
                        mAnimationDrawable.stop();
                        choose_product_image_load.setVisibility(View.GONE);
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                list.clear();

                                JSONArray array1 = response
                                        .getJSONArray("data");
                                JSONArray array = array1.getJSONArray(0);
                                for (int i = 0; i < array.length(); i++) {
                                    JSONObject OBJECT = array.getJSONObject(i);
                                    news mnews = new news();
                                    mnews.setName(OBJECT
                                            .getString("parent_name"));
                                    mnews.setId(OBJECT.getString("id"));
                                    mnews.setNews_title(OBJECT
                                            .getString("title"));
                                    mnews.setPath(OBJECT.getString("imgurl"));
                                    list.add(mnews);
                                }
                                handler.sendEmptyMessage(1);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    public void get_qiye_data_more() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("page", page + "");
        parms.addBodyParameter("cid", cid + "");
        parms.addBodyParameter("k", text_product_context);
        httpUtils.send(HttpMethod.POST, Contant.product_liebiao, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        Toast.makeText(getActivity(), "网络异常", Toast.LENGTH_SHORT).show();
                        mAnimationDrawable.stop();
                        choose_product_image_load.setVisibility(View.GONE);
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        Log.i("ssssss", arg0.result);
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                JSONArray array1 = response
                                        .getJSONArray("data");
                                JSONArray array = array1.getJSONArray(0);
                                if (array.length() == 0) {
                                    Toast.makeText(getActivity(), "没有更多数据哦", Toast.LENGTH_SHORT)
                                            .show();
                                } else {
                                    for (int i = 0; i < array.length(); i++) {
                                        JSONObject OBJECT = array
                                                .getJSONObject(i);
                                        news mnews = new news();
                                        mnews.setName(OBJECT
                                                .getString("parent_name"));
                                        mnews.setId(OBJECT.getString("id"));
                                        mnews.setNews_title(OBJECT
                                                .getString("title"));
                                        mnews.setPath(OBJECT
                                                .getString("imgurl"));
                                        list.add(mnews);
                                    }
                                }
                                handler.sendEmptyMessage(2);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    public void get_fenlei_sanji_tag(final int index,
                                     final ArrayList<YiJi_Class> list, final ListView listview) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("cid", cid);

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.product_tag, params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        list.clear();
                        if (array.length() == 0) {
                            listview.setVisibility(View.GONE);
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject OBJECT = array
                                        .getJSONObject(i);
                                YiJi_Class mYiJi_Class = new YiJi_Class();
                                mYiJi_Class.setId(OBJECT.getInt("id"));
                                mYiJi_Class.setName(OBJECT
                                        .getString("name"));
                                list.add(mYiJi_Class);
                            }
                            handler.sendEmptyMessage(index);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    @Override
    public void onResume() {
        super.onResume();
        if (Main_SearchActivity.qiye_product_id == 1) {
            if (text_product_context.length() == 0) {
                product_choose_name.setText("选型大厅");
            } else {
                product_choose_name.setText(text_product_context);
            }
            XJApplication.cachThreadPool.execute(new Runnable() {

                @Override
                public void run() {
                    get_qiye_data();
                }
            });
            Main_SearchActivity.qiye_product_id = 0;
        }
        if (Contant.come_from_fuwuDetail == 2) {
            get_shengji_company3();
            Contant.come_from_fuwuDetail = 0;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        handler.removeCallbacksAndMessages(null);

    }

    /**
     * 判断是否升级为企业用户
     */
    public void get_shengji_company3() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        httpUtils.send(HttpMethod.POST, Contant.is_shengji_compny, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        // Toast.makeText(getActivity(),"网络异常",1).show();
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject obj = new JSONObject(arg0.result);
                            if (obj.getInt("status") == 3) {
                                // 如果返回3表明升级企业通过
                                if (PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("FP")
                                        || PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("AP")) {
                                    // 记录的还是个人 账号
                                    PreferenceEngine.getInstance().putBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false);
                                }
                            }
                            // 判断 个人升级为企业的标记
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_XIANJI_STATUS, obj.getInt("status"));

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
}
